/* Copyright (C) 2021 Rain */

/* This file is part of XNIX. */

/* 
  XNIX is free software: you can redistribute it and/or modify 
  it under the terms of the GNU General Public License as published by 
  the Free Software Foundation, either version 3 of the License, or 
  (at your option) and later version. 
*/

/*
  XNIX is distributed in the hope that it will be useful, 
  but WITHOUT ANY WARRANTY; without even the implied warranty of 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  GNU General Public License for more details. 
*/

/*
  You should have received a copy of the GNU General Public License 
   along with XNIX. If not, see <https://www.gnu.org/licenses/>.  
*/




#ifndef _TTY_H
#define _TTY_H

#include <kernel/init.h>
#include <kernel/types.h>

int tty_read(struct tty *, char *, size_t);
int tty_write(struct tty *, char *, size_t);


struct tty {
	struct fifo *input_fifo;

	/* unreadable (wr-only) */
#define T_NORD 		0x01
	/* tty_read returns character / line */
#define T_COOKED 	0x02

	/* put the input character to screen (in tty_read) */
#define T_INPUT_BACK	0x04

	__uint8_t mode;

	/* the controller process id */
	__uint32_t ctl;

	__uint8_t vx, vy;

	int (* putc) (struct tty *, char c);

	struct tty *next;
};

/* tty0: system console (0xb8000)  tty1: serial port 0 (if exists) */
extern struct tty tty0, tty1;

/* point to that tty the print uses. */
extern struct tty *stdout;

#endif

